package com.ztz.controller;

import com.sun.tracing.dtrace.Attributes;
import com.ztz.services.Testservices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class Test {

    @Autowired
    private Testservices testservices;

    //首页
    @RequestMapping(value = "/importlist1.html")
    public ModelAndView index(){
        ModelAndView modelAndView=new ModelAndView("/tests");
        return modelAndView;
    }
    //上传
    @RequestMapping(value = "/drimport1.html")
    @ResponseBody
    public Map<String, Object> importExcel(@RequestParam(value="drfile",required = false) MultipartFile file, HttpServletRequest request, HttpServletResponse response){
        Map<String, Object> map = new HashMap<String, Object>();
        System.out.println(file);
        String result = testservices.readExcelFile(file);
        map.put("message", result);
        return map;
    }
}
